// MESSAGE HEARTBEAT support class

#pragma once

namespace mavlink {
namespace fppa {
namespace msg {

/**
 * @brief HEARTBEAT message
 *
 * The heartbeat message shows that a system is present and responding. The type of the MAV and Autopilot hardware allow the receiving system to treat further messages from this system appropriate (e.g. by laying out the user interface based on the autopilot).
 */
struct HEARTBEAT : mavlink::Message {
    static constexpr msgid_t MSG_ID = 0;
    static constexpr size_t LENGTH = 111;
    static constexpr size_t MIN_LENGTH = 111;
    static constexpr uint8_t CRC_EXTRA = 125;
    static constexpr auto NAME = "HEARTBEAT";


    uint8_t system_status; /*<  System status flag, see MAV_STATE ENUM */
    uint8_t mavlink_version; /*<  MAVLink version */
    float cpu_load; /*<  System CPU load */
    uint8_t motor_status; /*<  motor status */
    uint8_t imu_status; /*<  imu status */
    uint8_t beacon_status; /*<  beacon status */
    uint8_t attitude_ctrl_status; /*<  attitude control status */
    uint8_t signal_ctrl_status; /*<  signal control status */
    std::array<uint8_t, 50> antenna_version; /*<  antenna version. */
    std::array<uint8_t, 50> software_version; /*<  software version. */


    inline std::string get_name(void) const override
    {
            return NAME;
    }

    inline Info get_message_info(void) const override
    {
            return { MSG_ID, LENGTH, MIN_LENGTH, CRC_EXTRA };
    }

    inline std::string to_yaml(void) const override
    {
        std::stringstream ss;

        ss << NAME << ":" << std::endl;
        ss << "  system_status: " << +system_status << std::endl;
        ss << "  mavlink_version: " << +mavlink_version << std::endl;
        ss << "  cpu_load: " << cpu_load << std::endl;
        ss << "  motor_status: " << +motor_status << std::endl;
        ss << "  imu_status: " << +imu_status << std::endl;
        ss << "  beacon_status: " << +beacon_status << std::endl;
        ss << "  attitude_ctrl_status: " << +attitude_ctrl_status << std::endl;
        ss << "  signal_ctrl_status: " << +signal_ctrl_status << std::endl;
        ss << "  antenna_version: [" << to_string(antenna_version) << "]" << std::endl;
        ss << "  software_version: [" << to_string(software_version) << "]" << std::endl;

        return ss.str();
    }

    inline void serialize(mavlink::MsgMap &map) const override
    {
        map.reset(MSG_ID, LENGTH);

        map << cpu_load;                      // offset: 0
        map << system_status;                 // offset: 4
        map << mavlink_version;               // offset: 5
        map << motor_status;                  // offset: 6
        map << imu_status;                    // offset: 7
        map << beacon_status;                 // offset: 8
        map << attitude_ctrl_status;          // offset: 9
        map << signal_ctrl_status;            // offset: 10
        map << antenna_version;               // offset: 11
        map << software_version;              // offset: 61
    }

    inline void deserialize(mavlink::MsgMap &map) override
    {
        map >> cpu_load;                      // offset: 0
        map >> system_status;                 // offset: 4
        map >> mavlink_version;               // offset: 5
        map >> motor_status;                  // offset: 6
        map >> imu_status;                    // offset: 7
        map >> beacon_status;                 // offset: 8
        map >> attitude_ctrl_status;          // offset: 9
        map >> signal_ctrl_status;            // offset: 10
        map >> antenna_version;               // offset: 11
        map >> software_version;              // offset: 61
    }
};

} // namespace msg
} // namespace fppa
} // namespace mavlink
